package com.aixin.project.util;
import java.util.Date;
import java.util.TimerTask;

import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.log4j.Logger;

public class MemcachedTimerTask extends TimerTask {

    private static final Logger  logger = Logger.getLogger(MemcachedTimerTask.class);
    private String cacheClassName = "";


    public MemcachedTimerTask(String classname){
        cacheClassName = classname;
    }
	@Override
	public void run() {
		// if memcached server(s) are back, we need to clear all local caches
		// in order to save memory and avoid duplicate caching
        if(cacheClassName.equals(AxMemcached.class.getName())){
            boolean b = AxMemcached.check();
            if (b) AxMemcached.purgeCache();
            else {
                logger.info("\n" + DateFormatUtils.format(new Date(),"yyyyMMdd-HHmmss") +" "+ cacheClassName + " Memcached status: OFF\n");
            }
        }
	}

}
